package com.service;

import java.sql.Timestamp;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.dao.IAmsBisAlmInfoDao;
import com.dao.IAmsRetToolHbtDao;
import com.icim.service.ICIMBaseService;
import com.model.Ams_ret_tool_hbt;
import com.model.Ret_box;
import com.model.Ret_tool_st;
import com.rtnBean.NotFoundRtnBeen;
import com.tx.Amshbt.AmshbtI;
import com.tx.Amshbt.AmshbtIA;
import com.tx.Amshbt.AmshbtO;
import com.util.MqOpe;
import com.util.Util;

import static com.def.GenericDef.*;

import org.springframework.context.annotation.Scope;

@Scope("prototype")
@Service("AmshbtWD")
public class AmshbtWD extends ICIMBaseService{
	private static Logger logger = Logger.getLogger(AmshbtWD.class);
	private static String TX_NAME = T_AMSHBTWD;

	private MqOpe mqOpe;

	private String gszMsgBuf = "";
	private Timestamp gEvtTimestamp;

	@Autowired
	private IAmsRetToolHbtDao amsRetToolHbtDao;
	@Autowired
	private IAmsBisAlmInfoDao amsBisAlmInfoDao;

	@Transactional
	public void subMainProc() {
		long rtnCode = _NORMAL;
		gszMsgBuf = "";
		gEvtTimestamp = Util.getCurrentTimestamp();
		mqOpe = new MqOpe();
		logger.info("[" + TX_NAME + "] run...");
		
		try {
			rtnCode = subMainProc2();
			if (rtnCode != _NORMAL) {
				TransactionAspectSupport.currentTransactionStatus()
						.setRollbackOnly();
				logger.error(String.valueOf(rtnCode) + " " + gszMsgBuf);
			} else {
				amsRetToolHbtDao.flushCurSession();
			}
		} catch (Exception ex) {
			TransactionAspectSupport.currentTransactionStatus()
					.setRollbackOnly();
			logger.error(ex.toString());
			logger.error(Util.stackTraceToString(ex));
		}
		
		logger.info("[" + TX_NAME + "] finish...");
	}

	private long subMainProc2() {
		long lRc = _NORMAL;

		lRc = getHeartBeatList();
		if (_NORMAL != lRc) {
			return lRc;
		}

		return lRc;
	}

	private long getHeartBeatList() {
		long lRc = _NORMAL;
//		String sql = "FROM Ret_box where box_stat='WAIT' and bnk_flg='0' "
//				+ "and nx_toolg_id_fk ='" +  
//				+ "'";
// 
//		List<Ret_box> RetBoxList = amsRetToolHbtDao.comTblRead2nd(sql);
		return _NORMAL;
	}

	public String subMainProc(String arg0) {
		// TODO Auto-generated method stub
		return null;
	}

}
